/**
 * Created by koudaiwang on 2017/6/20.
 */

var Admin = require('./dao').Admin;
module.exports = {

    // adminLogin: function (admin) {
    //     var query = {};
    //     if (admin) {
    //         query.adminName = admin.adminName;
    //     }
    //     return Admin.find(query).sort({ _id: -1 }).exec();
    // },

    addAdmin: function create(admin) {
        admin['webLogin'] = '';
        admin['webLoginTime'] = '';
        admin['iOSLogin'] = '';
        admin['iOSLoginTime'] = '';
        admin['androidLogin'] = '';
        admin['androidLoginTime'] = '';
        return Admin.create(admin).exec();
    },

    delAdmin: function (adminName) {
        var query = {};
        if (adminName) {
            query.username = adminName;
        }
        return Admin.remove(query).exec();
    },

    getAdminByName: function (adminName) {
        var query = {};
        if (adminName) {
            query.username = adminName;
        }
        return Admin.find(query).sort({ _id: -1 }).exec();
    },

    getAllAdmin: function () {
        return Admin.find().sort({ level: -1 }).exec();
    },

    updateLoginStatus: function (userID, data) {
        return Admin.update({ _id: userID }, { $set: data }).exec();
    }



};